<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="$emit('clear-search-histories')">全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow=false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow=true"  />
    </van-cell>
    <van-cell v-for="(itme,index) in searchHistories" 
    :key="index" 
     :title="itme"
     @click="onSearchItemClick(itme,index)"
     >
      <van-icon name="close" v-show="isDeleteShow" />
    </van-cell>
  </div>
</template>

<script>
export default {
  name: 'SearchHistory',
  components: {},
  props: {
    searchHistories:{
      type: Array,
      required:true
    }
  },
  data () {
    return {
      isDeleteShow:false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onSearchItemClick(itme,index){
      if(this.isDeleteShow){
        this.searchHistories.splice(index,1)
      }else{
        this.$emit('search', itme);
      }
    }
  }
}
</script>

<style scoped lang="less"></style>